package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:lyd
 **/
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {


    @Autowired
    BaseTrademarkService baseTrademarkService;

    /**
     * 分页查询品牌
     *
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/{current}/{size}")
    public Result getPage(@PathVariable("current") Long current,
                          @PathVariable("size") Long size) {
        Page<BaseTrademark> page = baseTrademarkService.page(new Page<BaseTrademark>(current, size));
        return Result.ok(page);
    }

    /**
     * 删除品牌
     *
     * @param imgId
     * @return
     */
    @DeleteMapping("/remove/{imgId}")
    public Result remove(@PathVariable("imgId") Long imgId) {
        baseTrademarkService.removeById(imgId);
        return Result.ok();
    }

    @GetMapping("/get/{imgId}")
    public Result get(@PathVariable("imgId") Long imgId) {
        BaseTrademark baseTrademark = baseTrademarkService.getById(imgId);
        return Result.ok(baseTrademark);
    }

    @PostMapping("/save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @PutMapping("/update")
    public Result update(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    /**
     * 获取品牌列表
     * @return
     */
    @GetMapping("/getTrademarkList")
    public Result getTrademarkList(){
        return Result.ok(baseTrademarkService.list());
    }
}
